package org.example.com.RocketMq.smallCase;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class RocketMqProduct {
    public static void main(String[] args) throws Exception {
        // 1. 实例化消息生产者 producer
        DefaultMQProducer producer = new DefaultMQProducer("group_producer_demo1");
        // 2. 设置 nameServer 的地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 关闭 VIP 通道
//        producer.setVipChannelEnabled(false);
        producer.setSendMsgTimeout(3000);
        // 3. 启动 Producer 实例
        producer.start();
        for (int i = 0; i < 10; i++) {
            // 4. 创建消息 message
            Message message = new Message("Topic_Demo", "Tags", "Hello RocketMQ" + i, "next".getBytes(RemotingHelper.DEFAULT_CHARSET));
            // 5. 发送消息
            SendResult result = producer.send(message);
            System.out.println(result);
        }
        // 6. 关闭 producer
        producer.shutdown();
    }
}
